home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / driverss.zip / SERSUB.ASM < prev    next >
Assembly Source File  |  1991-01-25  |  2KB  |  97 lines

  1. open:
  2.     ;Set line control register: 8 bits, no parity
  3.     mov    al,LCR_8BITS
  4.     mov    dx,io_addr    ; point to chip 
  5.     add    dx,LCR        ; add offset to line control register
  6.     out    dx,al        ; set characteristics
  7.  
  8.     ;Set modem control register: assert DTR, RTS
  9.     mov    al,MCR_DTR or MCR_RTS
  10.     mov    dx,io_addr        ; point to chip 
  11.     add    dx,MCR            ; add offset to modem control register
  12.     out    dx,al            ; set characteristics
  13.  
  14. ;compute the divisor given the baud rate.
  15.     mov    dx,baudclk+2
  16.     mov    ax,baudclk
  17.     mov    bx,0
  18. asy_speed_1:
  19.     inc    bx
  20.     sub    ax,baud_rate
  21.     sbb    dx,baud_rate+2
  22.     jnc    asy_speed_1
  23.     dec    bx
  24.     add    ax,baud_rate
  25.     adc    dx,baud_rate+2
  26.     or    ax,dx
  27.  
  28.     ;Purge the receive data buffer
  29.     mov    dx,io_addr            ;point to chip
  30.     add    dx,RBR
  31.     in    al,dx
  32.  
  33.     mov    ah,LCR_DLAB        ;Turn on divisor latch access bit
  34.     mov    dx,io_addr            ;point to chip
  35.     add    dx,LCR
  36.     call    setbit
  37.  
  38.     mov    al,bl            ;Load the two bytes of the divisor.
  39.     mov    dx,io_addr            ;point to chip
  40.     add    dx,DLL
  41.     out    dx,al
  42.     mov    al,bh
  43.     mov    dx,io_addr            ;point to chip
  44.     add    dx,DLM
  45.     out    dx,al
  46.  
  47.     mov    ah,LCR_DLAB        ;Turn off divisor latch access bit
  48.     mov    dx,io_addr            ;point to chip transmit 
  49.     add    dx,LCR
  50.     call    clrbit
  51.  
  52.     clc                ;indicate no errors.
  53.     ret
  54.  
  55. pr_ch:
  56.     push    ds    ; save ds so we can restore later
  57.     push    cs    ; push cs and pop into ds
  58.     pop    ds
  59.     push    dx    ; save dx so we can use it to point at i/o port
  60.     pushf        ; save flags then inhibit interrupts
  61.     cli
  62.     push    ax    ; save ax (al contains or character)
  63. ;
  64. ;    Now wait for holding register to empty
  65. ;
  66.     mov    dx,io_addr    ;point to chip line status register
  67.     add    dx,LSR        ; set up to check for an empty buffer
  68. xmit_top:
  69.     in    al, dx        ; get line status
  70.     test    al,LSR_THRE    ; check if holding register empty
  71.     jnz    xmit_done    ; yes so we can go and output
  72.     jmp    xmit_top    ; holding register full still so loop
  73.  
  74. xmit_done:    ; end of loop - holding register now empty
  75.  
  76.     pop    ax        ; now get our character
  77.     mov    dx,io_addr    ; point to chip
  78.     add    dx,THR        ; add offset to transmit holding register
  79. ; xmit a character
  80.     out    dx, al        ; and output our character
  81.     popf            ; restore flags (and interrupt state)
  82.     pop    dx        ; restore dx
  83.     pop    ds        ; restore ds to original value
  84.     ret
  85.  
  86. ;
  87. ;    NOW SOME DATA AREAS
  88. ;
  89.  
  90. io_addr        dw    03f8h,0        ; I/O address for COM1.
  91. baud_rate    dw    4b00h,0        ; We support baud rates higher than 65535.
  92. baudclk        label    word
  93.         dd    115200        ;1.8432 Mhz / 16
  94.  
  95.  
  96.  
  97.